<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>文章编写</title>
    <script src="jquery/jquery-3.6.0.min.js"></script>
    <link href="bootstrap-4.6.1-dist/css/bootstrap.min.css"
          rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="css/self.css">
    <link rel="stylesheet" href="bootstrap-4.6.1-dist/css/bootstrap.min.css" type="text/css">
    <link rel="stylesheet" href="css/font-awesome.min.css">
    <link rel="stylesheet" href="lib/editormd/css/editormd.min.css">
</head>
<!--导航栏-->
<nav class="navbar navbar-expand-md navbar-dark bg-dark">
    <a class="navbar-brand self-padding-first-border"><img src="./img/TimberBlog.svg" width="150px" height="30px"></img></a>
    <button class="navbar-toggler" id="indexBtn" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <ul class="navbar-nav mr-auto">
            <!--            主页-->
            <li class="nav-item">
                <a class="nav-link self-padding-other-border" href="index.html">
                    <i class="fa fa-home"></i>主页
                    <!--                    <span class="sr-only">(current)</span>-->
                </a>
            </li>
            <!--            分类-->
            <li class="nav-item">
                <a class="nav-link self-padding-other-border" href="type.html">
                    <i class="fa fa-folder-open"></i>分类
                </a>
            </li>
            <!--标签-->
            <li class="nav-item">
                <a class="nav-link self-padding-other-border" href="http://localhost:8088/demo/label.html">
                    <i class="fa fa-bookmark"></i>标签
                </a>
            </li>

            <!--            时间轴-->
            <li class="nav-item">
                <a class="nav-link self-padding-other-border" href="timetable.html">
                    <i class="fa fa-calendar"></i>时间轴
                </a>
            </li>
        </ul>
        <!--        搜索按钮-->
        <form class="form-inline my-2 my-lg-0  self-padding-search-border">
            <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
            <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
        </form>
        <ul class="navbar-nav">
            <li class="nav-item">
                <a class="nav-link" href="selfInf.html">
                    <i class="fa fa-user"></i>个人中心
                </a>
            </li>
            <!--编写文章-->
            <li class="nav-item">
                <a class="nav-link self-padding-other-border" href="editor.html">
                    <i class="fa fa-keyboard-o"></i>文章编辑
                </a>
            </li>
        </ul>
    </div>
</nav>
<!--内容-->
<div class="container" style="height:auto;padding-top:2em;">
    <form id="blog-form">
<!--            文章标题-->
        <div class="form-group row">
            <input type="text" class="form-control" placeholder="文章标题" name="title">
        </div>
<!--        文章封面图-->
        <div class="form-group row">
            <input type="text" class="form-control" placeholder="封面图地址" name="cover">
        </div>
<!--            文章内容-->
        <div class="form-group row" name="content">
            <div id="md-content" style="z-index: 1 !important;">
                <textarea placeholder="博客内容" id="content" name="content" style="display:none"></textarea>
            </div>
        </div>
<!--            提交日期-->
        <div class="form-group row">
            <label class="col-form-label col-2 text-center">请选择提交日期：</label>
            <div class="col-3">
                <input type="date" id="date" name="date"  class="form-control">
            </div>
        </div>
<!--            按钮-->
        <div class="form-group row" style="float:right">
            <button type="reset" class="btn btn-secondary">重置</button>
            <button type="button" id="btnReg" class="btn btn-secondary">保存</button>
            <button type="button" id="publish-btn" class="btn btn-secondary">发布</button>
        </div>
    </form>
    <br><br><br><br><br>
</div>

<!--底部-->
<footer>
    <div class="container">
        <br>
        <h6 class="text-center" style="color:white;font-family:'Microsoft YaHei UI'">Copyright © 2021 By TimberBlog</h6>
    </div>
</footer>
<script src="js/jquery-3.6.0.min.js"></script>
<script src="lib/editormd/editormd.min.js"></script>
<script src="bootstrap-4.6.1-dist/js/bootstrap.js"></script>
<script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
<script>
    //markdown编辑器初始化
    var contentEditor;
    $(function() {
        testEditor = editormd("md-content", {
            width   : "100%",
            height  : 640,
            syncScrolling : "single",
            path    : "lib/editormd/lib/",

            /**下述为新增，上面一行记得加逗号结束*/
            /*指定需要显示的功能按钮*/
            toolbarIcons : function() {
                return ["undo", "redo", "|","bold", "italic","ucwords","uppercase","lowercase","|","h1","h2","h3","h4","h5","h6","|","list-ul","list-ol","table","datetime","hr",  "||",  "watch", "fullscreen", "preview", "releaseIcon", "index"]
            },

            /*自定义功能按钮，下面我自定义了2个，一个是发布，一个是返回首页*/
            toolbarIconTexts : {
                releaseIcon : "<span bgcolor=\"gray\">发布</span>",
                index : "<span bgcolor=\"red\">返回首页</span>",
            },

            /*给自定义按钮指定回调函数*/
            toolbarHandlers:{
                releaseIcon : function(cm, icon, cursor, selection) {
                    contentCommit();//提交表单代码在下面
                    console.log("日志输出 testIcon =>", this, cm, icon, cursor, selection);
                },
                index : function(){
                    window.location.href = '返回首页的路径.html';
                },
            }
        });
    });



</script>
<!--<script>-->
<!--    jQuery(function () {-->
<!--        jQuery("#publish-btn").click(function () {-->
<!--            let form=jQuery("#form").serialize();-->
<!--            jQuery.post("user/editor",form,function (rst) {-->
<!--            })-->
<!--        })-->
<!--    })-->
<!--</script>-->
</body>
<script src="jquery/jquery-3.6.0.min.js"></script>
<script>
    jQuery(function () {
        jQuery("#btnReg").click(function () {
            //获取页面中控件的数据
            //1.必须在<form></form>之间
            //2.必须有name属性
            let form=jQuery("#blog-form").serialize();
            //向服务器发请求，并获取响应结果
            //rst表示服务器返回的数据
            jQuery.post("user/written",form,function (rst) {
                if(rst==1) {
                    alert("保存成功");
                }else{
                    alert("保存失败");
                }
            });
        });
    })
</script>
</html>